<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
</head>
<body class="no-skin">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">


    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-left">

                            <button class="btn btn-sm btn-info" id="query">条件搜索</button>
                            <button class="btn btn-sm btn-primary" id="approval-item">项目立项</button>
                        <%-- <shiro:hasPermission name="modules:sys:huashu:query"></shiro:hasPermission> --%>
                        <%--<button class="btn btn-sm btn-success" id="create">创建任务</button>--%>
                            <button class="btn btn-sm btn-default" id="edits">查看详情或修改</button>
                            <button class="btn btn-sm btn-info" id="singn-Task">签收批转</button>
                            <button class="btn btn-sm btn-danger" id="fallback-btn">回退</button>
                            <button class="btn btn-sm  btn-warning" id="cancel-task">撤销任务</button>
                            <button class="btn btn-sm btn-info" id="creatTaskSituation">添加落实情况</button>
                            <button class="btn btn-sm btn-success" id="exportJobs">导出表</button>


                            <%--<button class="btn btn-sm btn-info" id="createLog">任务催办</button>
                                <button class="btn btn-sm btn-danger" id="feedback" >反馈领导</button>
                                <button class="btn btn-sm btn-info" id="restartjob">重新督查</button>
                                <button class="btn btn-sm btn-success" id="createRecord">添加完成情况</button>--%>
                            <button class="btn btn-sm btn-danger" id="delete" style="display: none;">删除</button>

                            <%--<shiro:hasPermission name="modules:sys:dept:excel">
                                <button class="btn btn-sm btn-pink" id="export">导出</button>
                            </shiro:hasPermission>--%>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
                <div class="row" style="margin-left: 2px;">
                    * 双击列表可查看详情
                </div>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div><!-- /.main-container -->
</div>

<!-- footer -->
<%@ include file="/WEB-INF/views/include/footer.jsp" %>

<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/jobmanages"></s:url>/"
    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = ['任务名称', "任务状态", "承办单位", "责任人", "是否及时办结", "督查组绩效得分", "责任单位绩效得分", '任务单号', "开始日期",
        "结束日期", "计划开始时间", "计划结束时间", '到期日期', '任务内容', "责任单位", "责任人手机号", "经办人", "经办人手机号", "任务时间",
        "督查组类别", "督查组成员", "手机号", "佐证材料"

    ];
    var colModel = [
        {name: 'taskName', index: 'taskName', width: 160, editable: true},//任务名称
        {name: 'aaa001', index: 'aaa001', width: 160, editable: true, formatter: aa10Fmatter, cellattr: addCellAttr},//任务状态
        {name: 'resDept', index: 'resDept', width: 160, editable: true},//承办单位
        {name: 'resUser', index: 'resUser', width: 160, editable: true},//责任人
        {name: 'taskResult', index: 'taskResult', width: 160, editable: true, formatter: taskResultFmatter},//是否及时办结
        {name: 'supervisionScore', index: 'supervisionScore', width: 160, editable: true},//督查组绩效得分
        {name: 'respScore', index: 'respScore', width: 160, editable: true},//责任单位绩效得分
        {name: 'sysId', index: 'taskName', width: 200, editable: true, key: true},//任务单号
        {name: 'startDate', index: 'startDate', width: 160, editable: true},//开始时间
        {name: 'endDate', index: 'endDate', width: 160, editable: true},//结束时间
        {name: 'planStartDate', index: 'planStartDate', width: 160, editable: true},//计划开始时间
        {name: 'planEndDate', index: 'planEndDate', width: 160, editable: true},//计划结束时间
        {name: 'expirationDate', index: 'expirationDate', width: 160, editable: true},//任务到期时间
        {name: 'taskContent', index: 'taskContent', width: 160, editable: true},//任务内容
        {name: 'resDept', index: 'resDept', width: 160, editable: true},//责任单位
        {name: 'resPhone', index: 'resPhone', width: 160, editable: true},//责任人手机号码
        {name: 'operatorUser', index: 'operatorUser', width: 160, editable: true},//经办人
        {name: 'operatorPhone', index: 'operatorPhone', width: 160, editable: true},//经办人手机号码
        {name: 'taskDate', index: 'taskDate', width: 160, editable: true},//任务时间
        {name: 'groupCode', index: 'groupCode', width: 160, editable: true},//督查组类别
        {name: 'groupMember', index: 'groupMember', width: 160, editable: true},//督查组成员
        {name: 'phones', index: 'phones', width: 160, editable: true},//手机号
        {name: 'taxproof', index: 'taxproof', width: 160, editable: true, formatter: showbtnFmatter, edittype: 'custom'},//佐证材料


    ];
    //jqgrid的具体执行方法
    jqgrid({
        autoScroll: false,
        shrinkToFit: false,
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        onSelectRow: function (rowid, status) {
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i< rowids.length; i++){
                    if(rowids[i] ==  rowid){
                        flag = true;
                        continue;
                    }
                }
                if(!flag){
                    gridAddSelect(rowid);
                }
            }
            console.log(rowids);
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        }
    });
    //清空选中行
    $("#cancelChecked").click(function () {
        $("#gridTable").jqGrid('resetSelection');
        rowids=[];
    });
    var rowids = [];//选中行id
    /**
     * 取消选中
     */
    function gridRemoveSelect(rowid) {
        rowids.remove(rowid);
    }

    /**
     * 添加选中
     */
    function gridAddSelect(rowid) {
        rowids.push(rowid);
    }

    /**
     * 重写Array
     */
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };

    /**
     * 重写Array
     */
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };
  /*  //jqgrid的具体执行方法
    jqgrid({
        shrinkToFit: false,
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager"
    });*/

    //加载查询对话框
    $("#queryDialog").load(getUrl("filter"));

    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    var exportData = '';
    //显示查询对话框
    var queryDialog = $("#queryDialog");
    $("#query").click(function () {
        showDialog({
            dialogTitle: '查询',
            dialogBody: queryDialog,
            dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
                "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
                "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
        });
    });

    //具体查询方法
    function query() {

        exportData = $('#formDialog form').serialize();
        seachJqgird("#gridTable", "#formDialog form");
        $("#formDialog").modal('hide');
    }

    //更新操作
    $("#edits").click(function () {
        showEditView();
    });

    //项目立项
    $("#approval-item").click(function () {
        loadDialog({
            dialogTitle: '项目立项',
            dialogUrl: getUrl("approvalItem"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="approvalItemcreate()">确认</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //签收批转
    $("#singn-Task").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "签收办理",
            dialogUrl: getUrl("signTask"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="signtask()"  >签收</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });

    //签收任务。
    function signtask() {

        console.log("签收任务")
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("signTask"),
            tableId: "#gridTable",
            successMessage: "操作成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
    }

    //添加下载按钮
    function showbtnFmatter(cellvalue, options, rowObject) {
        if (cellvalue == null || cellvalue == "") {
            return "无上传材料";
        } else {


            var imgeHtml = " <button class=\"col-sm-5 btn btn-large btn-primary\"   onclick=\" downDetail('" + cellvalue + "'); \"   >下载</button> ";
            return imgeHtml;

        }
    }

    //下载按钮
    function downDetail(id) {
        //alert(id);
        var url = "/filesUpload/download/" + id;
        window.open(url);
    }

    /**落实情况按钮
     */
        $("#creatTaskSituation").click(function () {
            showEditDialog({
                tableId: "#gridTable",
                dialogTitle: "落实情况",
                dialogUrl: getUrl("creatTaskSituation"),
                dialogFoot: '<button type="button" class="btn btn-primary" onclick="situationEdit()"  >确定</button>' +
                    '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                    '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
                errorTitle: "消息对话框",
                errorMutiSelectMessage: '您当前选中多行，请重新选择',
                errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
                errorOk: '确定'
            });
        });
    /**
     * 反馈领导
     */
    /*   $("#feedback").click(function () {
           showEditDialog({
               tableId: "#gridTable",
               dialogTitle: "反馈领导",
               dialogUrl: getUrl("feedback"),
               dialogFoot: '<button type="button" class="btn btn-primary" onclick="feedbackLeader()"  >确定</button>' +
                   '<!--<button type="button" class="btn btn-pink" onclick="reset()">重置</button>-->' +
                   '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
               errorTitle: "消息对话框",
               errorMutiSelectMessage: '您当前选中多行，请重新选择',
               errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
               errorOk: '确定'
           });
       });*/


    /**重新开始
     */
    /*   $("#restartjob").click(function () {
           showEditDialog({
               tableId: "#gridTable",
               dialogTitle: "重新开始",
               dialogUrl: getUrl("rebuildjob"),
               dialogFoot: '<button type="button" class="btn btn-primary" onclick="Restartedit()"  >确定</button>' +
                   '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                   '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
               errorTitle: "消息对话框",
               errorMutiSelectMessage: '您当前选中多行，请重新选择',
               errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
               errorOk: '确定'
           });
       });*/

    /**添加完成情况
     */
    /*   $("#createRecord").click(function () {
           showEditDialog({
               tableId: "#gridTable",
               dialogTitle: "添加完成情况",
               dialogUrl: getUrl("createRespRecord"),
               dialogFoot: '<button type="button" class="btn btn-primary" onclick="recordEdit()" id="updatebtn" >确定</button>' +
                   '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                   '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
               errorTitle: "消息对话框",
               errorMutiSelectMessage: '您当前选中多行，请重新选择',
               errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
               errorOk: '确定'
           });
       });*/

    /**
     * ---------------------落实情况提交---------------
     * */
    //执行更新操作
        function situationEdit() {
            // if ($("#myform").data("changed")) {
            //     console.log("输入框修改过！")
            // } else {
            //     alert("没有修改过，无法提交！");
            //     return;
            // }
            console.log("落实情况")
            executeSaveOrUpdate({
                formId: "#formDialog form",
                dialogId: "#formDialog",
                url: getUrl("creatTaskSituation"),
                tableId: "#gridTable",
                successMessage: "操作成功",
                successTitle: '操作对话框',
                //failMessage: '更新失败',
                failTitle: '消息对话框'
            });
        //倒计时
        var btn = document.getElementById("submit");
        btn.disabled = true
        countdown(5);
        }

    /**
     * --------------完成情况记录提交事件 recordEdit ----------
     */
    /*  function recordEdit() {
          console.log("催办记录")
          executeSaveOrUpdate({
              formId: "#formDialog form",
              dialogId: "#formDialog",
              url: getUrl("createRespRecord"),
              tableId: "#gridTable",
              successMessage: "操作成功",
              successTitle: '操作对话框',
              //failMessage: '更新失败',
              failTitle: '消息对话框'
          });
      }*/
    /**
     *
     * 反馈领导
     */
    function feedbackLeader() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("feedback"),
            tableId: "#gridTable",
            successMessage: "发送成功",
            successTitle: '提示',
            //failMessage: '更新失败',
            failTitle: '提示'
        });
    }


    /**
     *-------------------------重新开始督查任务-----------------------
     */
    function Restartedit() {
        /*  if ($("#myform").data("changed")) {
                console.log("输入框修改过！")
            } else {
                alert("没有修改过，无法提交！");
                return;
            }*/
        console.log("更新操作")
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("rebuildjob"),
            tableId: "#gridTable",
            successMessage: "操作成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
    }

    //执行更新操作
    function edit() {
        console.log("更新操作")
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("edit"),
            tableId: "#gridTable",
            successMessage: "操作成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
    }

    //显示编辑对话框
    function showEditView() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "任务详情",
            dialogUrl: getUrl("edit"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="edit()" id="updatebtn" >确定</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }

    /*function showLogEditView() {
        console.log("ciban s sddskddj ")
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "更新对话框",
            dialogUrl: getUrl("createTaskLog"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="edit()" id="updatebtn" >更新</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',

        });
    }*/

    //显示编辑对话框
    function showView() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "更新对话框",
            dialogUrl: getUrl("edit"),

            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }

    /*
        $("#exportSummary").click(function () {
            // exportData=decodeURIComponent(exportData,true);//解码
            var url = "/export/ExportSummary" + '?' + exportData;
            console.log(exportData);
            window.open(url);

        });*/


    // 撤銷任務
    $("#cancel-task").click(function () {
        showDeleteDialog({
            url: getUrl("cancletask"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定撤销该任务/事项?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "撤销成功",
            successTitle: "消息对话框",
            //failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    });

    /**
     * freebacktask 回退任务。
     **/
    $("#fallback-btn").click(function () {
        showDeleteDialog({
            url: getUrl("freebacktask"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定回退该任务/事项?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "回退成功",
            successTitle: "消息对话框",
            //failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    });

    //删除
    $("#delete").click(function () {
        showDeleteView();
    });

    //显示删除对话框
    function showDeleteView() {
        showDeleteDialog({
            url: getUrl("delete"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    }

    //显示创建对话框
    $("#create").click(function () {

        loadDialog({
            dialogTitle: '手动新建任务',
            dialogUrl: getUrl("create"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">确认</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //保存数据
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("create"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            //failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    /**
     *
     * 项目立项
     *
     */
    function approvalItemcreate() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("approvalItemCreate"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            //failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }


    /**
     * 双击显示
     */
    /* $("#gridTable").dblclick(function (e) {
         showView();
     });*/

    /* $("#exportJobs").click(function () {
         var win = confirm("确认导出？");
         if (win == true) {
             //exportData = $('#formDialog form').serialize();
             var url = "/jobmanages/exportJobs"
             window.open(url);
         }
     });*/


    /**
     * 导出表头选择
     */
    $("#exportJobs").click(function () {
        loadDialog({
            dialogTitle: '导出表',
            dialogUrl: getUrl("formHead"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="exports()">确认</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    function exports() {
        var exportData = '';
        exportData = $('#formDialog form').serialize();
        console.log(exportData);
        var win = confirm("确认导出？");
        if (win == true) {
            var url = "/jobmanages/exportJobs?" + exportData;
            window.open(url);
        }
    }


    //转换code值
    function aa10Fmatter(cellvalue, options, rowObject) {
        if (cellvalue == "1") {
            return "有效任务";
        } else if (cellvalue == "0") {
            return "失效任务";
        } else if (cellvalue == '2') {
            return "回退任务";
        }
    }

    function addCellAttr(rowId, val, rawObject, cm, rdata) {

        if (rawObject.aaa001 == "0") {
            return "style='color:red'";
        }
        if (rawObject.aaa001 == "2") {
            return "style='color:blue'";
        }
    }

    function taskResultFmatter(cellvalue, options, rowObject) {
        if (cellvalue == "1") {
            return "已办结";
        } else if (cellvalue == "0") {
            return "未办结";
        }
    }

    //流程图表js
    $(function () {
        $(".nav>li:nth-child(10)").addClass("active");

        //管理员需有修改、回退、撤销任务的功能
        /* var userType =
        if (userType == "1") {
            $("#edits").css("display", "none");//修改
            $("#cancel-task").css("display", "none");//撤销
            $("#fallback").css("display", "none");//回退
        }*/
    })


</script>

</body>
</html>